<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class _Common {
	
	function index() {
		
		$CI =& get_instance();

		//---------------------------------------------------------------------------
		// 헤더값 세팅
		//---------------------------------------------------------------------------
		header("Content-Type: text/html; charset=".$CI->config->item('charset'));
		header("Expires: 0"); // rfc2616 - Section 14.21
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
		header("Cache-Control: pre-check=0, post-check=0, max-age=0"); // HTTP/1.1
		header("Pragma: no-cache"); // HTTP/1.0

		//---------------------------------------------------------------------------
		// 아이피 차단
		//---------------------------------------------------------------------------
		// if ((preg_match('/210.113.22/',$_SERVER['REMOTE_ADDR']) == 0)
			 // && (preg_match('/211.44.121/',$_SERVER['REMOTE_ADDR']) == 0)
			 // && (preg_match('/218.145.66.136/',$_SERVER['REMOTE_ADDR']) == 0)
			 // && (preg_match('/220.71.20.239/',$_SERVER['REMOTE_ADDR']) == 0)
			// ) {
			// die('허용되지 않은 IP로 접속하였습니다.');
		// }

		//---------------------------------------------------------------------------
		// 로그인 상태 체크 후 기본값 세팅
		//---------------------------------------------------------------------------
		$sess_userinfo = $CI->session->userdata('userinfo');
		if (!is_array($sess_userinfo)) {
			$arr_userinfo = array(
				'login_yn'   => 'N',
				'user_id'    => 'guests',
				'user_name'  => '손님',
				'nickname'   => '손님'
			);
			$CI->session->set_userdata('userinfo', $arr_userinfo);
		}

		$CI->data['sess_userinfo'] = $CI->session->userdata('userinfo');
		
		log_message('debug',"**** sess_userinfo=".print_r($CI->data['sess_userinfo'],TRUE));
		
		//---------------------------------------------------------------------------
		// 메뉴별 권한
		//---------------------------------------------------------------------------
		$seg      = $CI->uri->segment(1);	// 최상단 카테고리
		$user_id  = $CI->data['sess_userinfo']['user_id'];
		$login_yn = $CI->data['sess_userinfo']['login_yn'];
		
		// 로그인 페이지 말고는 일반 접속 차단
		if ($login_yn == 'N' && $seg != 'auth') {
			redirect('/auth/login');
		}
		
		if (DEBUG_MODE) $CI->output->enable_profiler(TRUE);
	}
}

/* End of file _Common.php */